package org.extremengine.shape;

import org.extremengine.common.Point;
import org.extremengine.common.Velocity;

/**
 * TODO ？矩形需要用宽度和高度来确定
 * @author yuxing
 *
 */
public class Rectangle extends Shape {

	// 从左上角开始顺时针方向的四个点
	private Point p1;
	private Point p2;
	private Point p3;
	private Point p4;

	/**
	 * 创建平行于坐标轴的长方形
	 * 
	 * @param x1
	 * @param x2
	 * @param y1
	 * @param y2
	 */
	public Rectangle(int x1, int x2, int y1, int y2) {
		this(new Point(x1, y1), new Point(x2, y1), new Point(x2, y2), new Point(x1, y2));
	}

	public Rectangle(Point p1, Point p2, Point p3, Point p4) {
		super();
		this.p1 = p1;
		this.p2 = p2;
		this.p3 = p3;
		this.p4 = p4;
	}

	public static Rectangle wrap(Shape shape) {
		throw new UnsupportedOperationException();
	}

	@Override
	public Point getBarycenter() {
		return new Point(p1.x + (p2.x - p1.x) / 2, p1.y + (p2.y - p1.y) / 2);
	}

	@Override
	public void transform(double deltax, double deltay) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void transform(Velocity v, long timePeirod) {
		double deltax = (v.getSpeedx() * timePeirod) / 1000;
		double deltay = (v.getSpeedy() * timePeirod) / 1000;
		throw new UnsupportedOperationException();
	}

	public double[] getXs() {
		return new double[] { p1.x, p2.x, p3.x, p4.x };
	}

	public double[] getYs() {
		return new double[] { p1.y, p2.y, p3.y, p4.y };
	}

	public Point getP1() {
		return p1;
	}

	public void setP1(Point p1) {
		this.p1 = p1;
	}

	public Point getP2() {
		return p2;
	}

	public void setP2(Point p2) {
		this.p2 = p2;
	}

	public Point getP3() {
		return p3;
	}

	public void setP3(Point p3) {
		this.p3 = p3;
	}

	public Point getP4() {
		return p4;
	}

	public void setP4(Point p4) {
		this.p4 = p4;
	}
	
	public double getWidth() {
		return this.p2.x - this.p1.x; 
	}
	
	public double getHeight() {
		return this.p3.y - this.p2.y;
	}
	
	public double getDiagonalLength() {
		return this.p3.distanceTo(this.p1);
	}

	@Override
	public Shape clone() {
		throw new UnsupportedOperationException();
	}
}
